#include <stdio.h>
#include <stdlib.h>

int main()
{
    int **matrix;
    int M, N;
    while (scanf("%d%d", &M, &N) == 2)
    {
        int i, j;

        //分配内存
        matrix = (int **)malloc(sizeof(int *) * M);
        if (matrix == NULL) /* 处理分配内存失败的情况 */
            exit(1);
        for (i = 0; i < M; i++) {
            *(matrix + i)  = (int *) malloc(sizeof(int) * N);
            if (*(matrix + i) == NULL)
                exit(1);
            for (j = 0; j < N; j++)
                scanf("%d", *(matrix + i) + j);
        }

        for (j = 0; j < N; j++) {
            for (i = 0; i < M; i++) {
                printf("%d ", *(*(matrix + i) + j));
            }
            printf("\n");
        }

        //释放内存
        for (i = 0; i < M; i++) {
            free(*(matrix + i));
            *(matrix + i) = NULL; //养成释放指针以后赋值为NULL的习惯
        }
        free(matrix);
        matrix = NULL;
    }
    return 0;
}
